home *** CD-ROM | disk | FTP | other *** search
- Path: grimsel.zurich.ibm.com!usenet
- From: wgk@zurich.ibm.com (Keith Whittingham)
- Newsgroups: comp.lang.c++
- Subject: Re: Did I Miss Something?
- Date: 4 Apr 1996 08:37:27 GMT
- Organization: IBM Research, ZRH
- Message-ID: <4k01o7$sl2@grimsel.zurich.ibm.com>
- References: <N.040396.105136.51@ix.netcom.com>
- Reply-To: wgk@zurich.ibm.com
- NNTP-Posting-Host: pine.zurich.ibm.com
- X-Newsreader: IBM NewsReader/2 v1.00
-
- In <N.040396.105136.51@ix.netcom.com>, jhewett@ix.netcom.com (Jerry Hewett) writes:
- >
- >class box {
- > int length;
- > int width;
- > char *line_of_text;
- >public:
- > box(char *input_line);
- > void set(int new_length, int new_width);
- > int get_area(void);
- >};
- >box::box(char *input_line)
- >{
- > length = 8;
- > width = 8;
- > line_of_text = input_line;
- >}
- >
- >main()
- >{
- > box small("small box ");
- >
- >}
- >
- >So far (the past three days) I've learned more from the Coronado Enterprises
- >C++ TUTOR than from all of the books I bought that were supposed to help me
-
- There is no memory allocation for the string: your assumption is wrong.
- I think the code you're are being given is not a very good example!
- The constructer would be better written:
-
-
- box::box(char *input_line)
- {
- length = 8;
- width = 8;
- line_of_text = strdup(input_line);
- }
-
- and a destructor...
-
- box::~box()
- {
- free(line_of_text);
- }
-
- Of course the C++ biggots will insist on using new and delete instead of
- strdup and free but that's all a matter of stlye.
-
- In general C++ itself does no more for you than C, no automatic memory
- allocation, no garbage collection etc. All in all that should lead to
- faster code but you do have to be thorough when writing the stuff.
-
- Keith
-
-
-